#!/bin/bash
set -e
mkdir -p httperf_data

static_page=/
app_data_page=happy

call_httperf()
{
	uri=$1
	port=$2
	nconn=$3
	rate=$4
	data_file=$5
	httperf --hog --server localhost --uri $uri --port $port --num-conn $nconn --rate $rate > httperf_data/$data_file
}

run_baseline()
{
	nconn=$1
	rate=$2

	echo "baseline apache static page n$nconn r$rate"
	call_httperf / 80 $nconn $rate baseline_apache_static_page_n${nconn}_r$rate.txt
	echo "baseline app page - apache n$nconn r$rate"
	call_httperf /app 80 $nconn $rate baseline_apache_app_page_n${nconn}_r$rate.txt
	echo "baseline app data page - apache n$nconn r$rate"
	call_httperf /app/$app_data_page 80 $nconn $rate baseline_apache_app_data_page_n${nconn}_r$rate.txt

	echo "baseline app page - django n$nconn r$rate"
	call_httperf / 8000 $nconn $rate baseline_django_app_page_n${nconn}_r$rate.txt
	echo "baseline app data page - django n$nconn r$rate"
	call_httperf /$app_data_page 8000 $nconn $rate baseline_django_app_data_page_n${nconn}_r$rate.txt
}

run_data()
{
	dataname=$1
	nconn=$2
	rate=$3

	echo "$dataname - apache app data page n$nconn r$rate"
	call_httperf /app/$app_data_page 80 $nconn $rate ${dataname}_apache_app_data_page_r$rate.txt
}

if [ "$1" == "" ] ; then
	echo "Usage $0 (baseline|dataN)"
	exit 1
fi

if [ "$1" == "baseline" ] ; then
	run_baseline 50 1
	run_baseline 1000 10
	run_baseline 1000 25
	run_baseline 1500 50
	run_baseline 5000 100
else
	run_data $1 50 1
	run_data $1 100 10
	run_data $1 100 25
	run_data $1 200 50
	run_data $1 1000 100
fi
